//
// Created by Administrator on 2020/11/3.
//

#ifndef GRAPH_BASIC_READGRAPH_H
#define GRAPH_BASIC_READGRAPH_H
#include <string>
#include <fstream>
#include <sstream>
#include <cassert>
using namespace std;
template <typename Graph>
class ReadGraph {
public:
    ReadGraph(Graph &graph, const string &filename){
        ifstream file(filename);
        string line;
        int V, E;

        assert(file.is_open());
        assert(getline(file, line));
        // 首先读入顶点数和边数
        stringstream ss(line);
        ss >> V >> E;
        assert(V == graph.V());
        // 读入每一条边
        for(int i = 0; i < E; ++i){
            assert(getline(file, line));
            stringstream ss(line);
            int a, b;
            ss >> a >> b;
            assert(a >= 0 && a < V);
            assert(b >= 0 && b < V);
            graph.addEdge(a, b);
        }

    }
};


#endif //GRAPH_BASIC_READGRAPH_H
